package com.ruoyi.project.jiaqin.supply.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.supply.domain.Supply;
import com.ruoyi.project.jiaqin.supply.service.ISupplyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 供应Controller
 * 
 * @author admin
 * @date 2020-12-28
 */
@Controller
@RequestMapping("/jiaqin/supply")
public class SupplyController extends BaseController
{
    private String prefix = "jiaqin/supply";

    @Autowired
    private ISupplyService supplyService;

    @RequiresPermissions("jiaqin:supply:view")
    @GetMapping()
    public String supply()
    {
        return prefix + "/supply";
    }

    /**
     * 查询供应列表
     */
    @RequiresPermissions("jiaqin:supply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Supply supply)
    {
        startPage();
        List<Supply> list = supplyService.selectSupplyList(supply);
        return getDataTable(list);
    }

    /**
     * 导出供应列表
     */
    @RequiresPermissions("jiaqin:supply:export")
    @Log(title = "供应", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Supply supply)
    {
        List<Supply> list = supplyService.selectSupplyList(supply);
        ExcelUtil<Supply> util = new ExcelUtil<Supply>(Supply.class);
        return util.exportExcel(list, "supply");
    }

    /**
     * 新增供应
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应
     */
    @RequiresPermissions("jiaqin:supply:add")
    @Log(title = "供应", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Supply supply)
    {
        return toAjax(supplyService.insertSupply(supply));
    }

    /**
     * 修改供应
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Supply supply = supplyService.selectSupplyById(id);
        mmap.put("supply", supply);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应
     */
    @RequiresPermissions("jiaqin:supply:edit")
    @Log(title = "供应", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Supply supply)
    {
        return toAjax(supplyService.updateSupply(supply));
    }

    /**
     * 删除供应
     */
    @RequiresPermissions("jiaqin:supply:remove")
    @Log(title = "供应", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(supplyService.deleteSupplyByIds(ids));
    }
}
